<template>
  <div>
    <form @submit.prevent="fn">
      <label>姓名：</label>
      <input type="text" v-model="form.username" /><br /><br />

      <label>年龄：</label>
      <input type="number" v-model="form.age" /><br /><br />

      <label>身高：</label>
      <input type="text" v-model="form.hight" />(米)<br /><br />

      <label>体重：</label>
      <input type="text" v-model="form.weight" />(公斤)<br /><br />

      <label>病史：</label>
      <input type="text" v-model="form.bs" /><br /><br />

      <button>诊断</button>
    </form>
    <p>
      患者 {{ form.username }} 的诊断结果：
      {{ form.jg }}
    </p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: '',
        age: '',
        hight: '',
        weight: '',

        bs: '',
        jg: '',
        BMI: '',
      },
    }
  },
  methods: {
    fn() {
      const BMI = (this.form.weight / this.form.hight) ^ 2
      console.log(BMI)

      BMI > 18.9 && BMI < 24.9
        ? (this.form.jg = '体重过轻')
        : (this.form.jg = '体重过重')
    },
  },
}
</script>
